package xjtu.se.articlecommunity.user.info.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import xjtu.se.articlecommunity.user.info.dto.MyDto;
import xjtu.se.articlecommunity.user.info.dto.UserDetail;
import xjtu.se.articlecommunity.user.info.dto.UserInfoDto;
import xjtu.se.articlecommunity.user.info.dto.CUserTab;

import java.util.List;

public interface UInfoDao {
    //@Select("select count(*) from t_user where u_id=#{u_id}")
    //UserDto
    @Update("update t_user set u_avatar=#{avatar} where u_id=#{u_key} or u_mail=#{u_key} or u_tel=#{u_key}")
    void setAvatar(@Param("u_key") String u_key,@Param("avatar") String filename);

    @Select("select u_tel,u_mail from t_user where u_id=#{u_id}")
    MyDto getTelMail(@Param("u_id") String u_id);

    @Select("select u_id,u_name,u_avatar,(select count(u_id) from t_follow where befollowed_u_id=#{u_id}) as fans_count,\n" +
            "(select count(befollowed_u_id) from t_follow where u_id=#{u_id}) as fol_count from t_user where u_id=#{u_id}")
    UserInfoDto finduser(@Param("u_id") String uid);

    @Select("select u_id,u_name,u_sex,u_birth,u_mark from t_user where u_id=#{u_id}")
    UserDetail finduserDetail(@Param("u_id") String uid);

    @Select("select ut.ut_id,ut_name from t_user_tab t, user_tab ut where ut.ut_id=t.ut_id and ut.u_id=#{u_id}")
    List<CUserTab> findUsertabs(@Param("u_id") String u_id);

    @Update("update t_user set u_name=#{u_name},u_sex=#{u_sex},u_birth=#{u_birth},u_mark=#{u_mark} where u_id=#{u_id}")
    void ChangeInfo(UserDetail userDto);

    //@Param("uid") String uid,@Param("uname") String uname,@Param("usex") String usex,@Param("ubirth") String ubirth,@Param("umark") String umark

    @Select("select u_passwd from t_user where u_id=#{uid}")
    String checkPassword(@Param("mail") String uid);

    @Select("select u_mail from t_user where u_id=#{uid}")
    String findmail(@Param("uid") String uid);

    @Update("update t_user set u_passwd=#{passwd} where u_id=#{uid}")
    void ChangePasswd(@Param("uid") String uid,@Param("passwd") String passwd);

    @Update("update t_user set u_mail=#{umail} where u_id=#{uid}")
    void ChangeMail(@Param("uid") String uid,@Param("umail") String umail);

    @Select("select u_tel from t_user where u_id=#{uid}")
    String findtel(@Param("uid") String uid);

    @Update("update t_user set u_passwd=#{passwd} where u_id=#{uid}")
    void ChangePasswd2(@Param("uid") String uid,@Param("passwd") String passwd);

    @Update("update t_user set u_tel=#{utel} where u_id=#{uid}")
    void Changetel(@Param("uid") String uid,@Param("utel") String utel);

}
